#include <iostream>
#include <map>
using namespace std;

//https://www.nowcoder.com/practice/351b87e53d0d44928f4de9b6217d36bb?tpId=230&tqId=39767&ru=/exam/oj

const int N = 100010;
int p[N];
int f[N], g[N];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)  cin >> p[i];

    f[0] = -p[0];
    for (int i = 1; i < n; i++)
    {
        f[i] = max(f[i - 1], -p[i]);
        g[i] = max(g[i - 1], p[i] + f[i - 1]);
    }

    cout << (g[n - 1] > 0 ? g[n - 1] : 0);

    return 0;
}
